/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferIc74;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferIc74Service;
import me.zhengjie.modules.transfer.domain.dto.TransferIc74QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferIc74Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-05-29
**/
@Service
@RequiredArgsConstructor
public class TransferIc74ServiceImpl extends ServiceImpl<TransferIc74Mapper, TransferIc74> implements TransferIc74Service {

    private final TransferIc74Mapper transferIc74Mapper;

    @Override
    public PageResult<TransferIc74> queryAll(TransferIc74QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferIc74Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferIc74> queryAll(TransferIc74QueryCriteria criteria){
        return transferIc74Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferIc74 resources) {
        transferIc74Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferIc74 resources) {
        TransferIc74 transferIc74 = getById(resources.getAaz086());
        transferIc74.copy(resources);
        transferIc74Mapper.updateById(transferIc74);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<String> ids) {
        transferIc74Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferIc74> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferIc74 transferIc74 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("系统跟踪流水号", transferIc74.getAaz341());
            map.put("转出地行政区划代码", transferIc74.getAab301());
            map.put("转入地行政区划代码", transferIc74.getAab299());
            map.put("联系函编号", transferIc74.getAae270());
            map.put("信息表编号", transferIc74.getAae405());
            map.put("转入险种类型", transferIc74.getAae241());
            map.put("转出险种类型", transferIc74.getAae140());
            map.put("转出地人员编号", transferIc74.getAac319());
            map.put("人员编号", transferIc74.getAac001());
            map.put("社会保障号码", transferIc74.getAac002());
            map.put("姓名", transferIc74.getAac003());
            map.put("性别", transferIc74.getAac004());
            map.put("出生日期", transferIc74.getAac006());
            map.put("户口所在地址", transferIc74.getAac010());
            map.put("转入地社保机构名称", transferIc74.getAaa146());
            map.put("转出地社保机构名称", transferIc74.getAab300());
            map.put("缴费起始时间", transferIc74.getAae030());
            map.put("缴费截止时间", transferIc74.getAae031());
            map.put("累计缴费月数", transferIc74.getAae199());
            map.put("被确认标志", transferIc74.getAae733());
            map.put("上传标志", transferIc74.getAae730());
            map.put("上传方经办人", transferIc74.getAae736());
            map.put("上传方经办时间", transferIc74.getAae739());
            map.put("人员转移流水号", transferIc74.getAae062());
            map.put("转出地社保机构联系电话", transferIc74.getAae005());
            map.put("个人账户基金转移额", transferIc74.getAic083());
            map.put("基金划转银行票据号", transferIc74.getAad019());
            map.put("转出日期", transferIc74.getAae035());
            map.put("转移数据来源", transferIc74.getAac306());
            map.put("人员参保关系ID", transferIc74.getAaz159());
            map.put("联网下载标志", transferIc74.getAae732());
            map.put("备注", transferIc74.getAae013());
            map.put("经办人", transferIc74.getAae011());
            map.put("经办时间", transferIc74.getAae036());
            map.put("经办机构", transferIc74.getAab359());
            map.put("业务日志ID", transferIc74.getAaz002());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
